package control;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultListModel;
import javax.swing.JList;

import dao.AbstractTable;

public class SwitchButtonListListener<T extends AbstractTable> implements
	ActionListener {

    private DefaultListModel listOut = null;
    private DefaultListModel listIn = null;
    private JList jListOut = null;

    public SwitchButtonListListener(DefaultListModel listOut,
	    DefaultListModel listIn, JList jListOut) {
	this.listOut = listOut;
	this.listIn = listIn;
	this.jListOut = jListOut;
    }

    public void actionPerformed(ActionEvent ae) {
	this.switcher(jListOut.getSelectedIndex());
    }

    private void switcher(int indice) {
	@SuppressWarnings("unchecked")
	T instd = (T) listOut.get(indice);

	if (indice >= 0) {
	    listIn.addElement(instd);
	    listOut.remove(indice);
	}
    }
}
